package com.zjsru.oneDay;

public class construct2DArray {
    public int[][] construct2DArray(int[] original, int m, int n) {
        int len = original.length;
        int[][] ints = new int[m][n];

        if(len !=  m*n){
            return new int[0][];
        }

        for (int i = 0, index = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                ints[i][j] =  original[index++];
            }
        }
        return ints;
    }
    public static void main(String[] args){
        construct2DArray construct2DArray = new construct2DArray();
        int[] original = new int[]{1,2,3,4};
        int m = 2;
        int n = 2;
        System.out.println(construct2DArray.construct2DArray(original,m,n));
    }
}
